﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Presentation.Shell.Interfaces;
using Microsoft.Practices.Prism.Regions;
using Presentation.Module.Setup.Interfaces;
using Presentation.Module.Setup.Interfaces.Views;

namespace Presentation.Module.Setup
{
    /// <summary>
    /// Interaction logic for SetupLandingPage.xaml
    /// </summary>
    public partial class SetupLandingPage : UserControl, IModuleLandingPage
    {
        // Inject region manager and ITaskCategories View. should actually create the view later on
        public SetupLandingPage(IRegionManager regionManager, ITaskCategoriesView taskCatagoriesView)
        {
            InitializeComponent();

            // Keep local references to the region manager and the task categories view
            this.RegionManager = regionManager;
            this.TaskCategoriesView = taskCatagoriesView;

            this.TaskCategoriesView.ViewExit += new Shell.Interfaces.ViewExit(TaskCategoriesView_ViewExit);

            // Add the task categories view to the region named MainRegion - This does not display the view, we need to call activate to display
            this.RegionManager.Regions["MainRegion"].Add(this.TaskCategoriesView);
        }

        void TaskCategoriesView_ViewExit()
        {
            RegionManager.Regions["MainRegion"].Activate(this);
        }

        private IRegionManager RegionManager { get; set; }
        private ITaskCategoriesView TaskCategoriesView { get; set; }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // Display the Task Categories View
            RegionManager.Regions["MainRegion"].Activate(TaskCategoriesView);
        }
        
        public object ParentView { get; set; }

        /// <summary>
        /// Occurs when [view exit].
        /// </summary>
        public event Shell.Interfaces.ViewExit ViewExit;

        /// <summary>
        /// Cancels the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void Cancel(object sender, System.Windows.RoutedEventArgs e)
        {
            if (this.ViewExit != null)
            {
                this.ViewExit.Invoke();
            }
        }
    }
}
